Calculating Diversifiable and Non-Diversifiable Risk of a Portolio


In [1]:
import numpy as np
import pandas as pd
from pandas_datareader import data as wb
import matplotlib.pyplot as plt

In [2]:
weights = np.array([32.94, 30.26, 11.77, 13.02, 9.00, 3.00])

In [3]:
tickers = ['ITSA3', 'GRND3', 'HGTX3', 'PSSA3', 'WEGE3', 'BVMF3']

sec_data = pd.DataFrame()

for t in tickers:
    sec_data[t] = wb.DataReader(t, data_source='google', start='2010-1-1')['Close']

In [8]:
sec_data.tail()


Out[8]:
ITSA3 GRND3 HGTX3 PSSA3 WEGE3 BVMF3
Date
2017-06-05 8.50 26.04 21.04 31.55 18.89 18.65
2017-06-06 8.64 26.05 21.38 31.06 18.76 18.55
2017-06-07 8.74 25.90 21.11 31.50 18.90 18.76
2017-06-08 8.60 25.86 20.50 31.33 18.74 18.59
2017-06-09 8.57 24.01 20.00 30.11 18.41 18.55

In [16]:
(sec_data / sec_data.iloc[0] * 100).plot(figsize = (15, 6))
plt.show()


Diversifiable Risk


In [10]:
sec_returns = np.log(sec_data / sec_data.shift(1))

In [17]:
ITSA3_var_a = sec_returns[['ITSA3']].var() * 250
GRDN3_var_a = sec_returns[['GRND3']].var() * 250
PSSA3_var_a = sec_returns[['PSSA3']].var() * 250
HGTX3_var_a = sec_returns[['HGTX3']].var() * 250
WEGE3_var_a = sec_returns[['WEGE3']].var() * 250
BVMF3_var_a = sec_returns[['BVMF3']].var() * 250

print(ITSA3_var_a, GRDN3_var_a, PSSA3_var_a, HGTX3_var_a, WEGE3_var_a, BVMF3_var_a)


ITSA3    0.199
dtype: float64 GRND3    0.095292
dtype: float64 PSSA3    0.108787
dtype: float64 HGTX3    0.215836
dtype: float64 WEGE3    0.222465
dtype: float64 BVMF3    0.193582
dtype: float64

In [ ]: